/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springblade.modules.filesys.controller;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.Api;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.filesys.entity.Sharing;
import org.springblade.modules.filesys.vo.CooperationSimpleVO;
import org.springblade.modules.filesys.vo.SharingSimpleVO;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.filesys.entity.Cooperation;
import org.springblade.modules.filesys.vo.CooperationVO;
import org.springblade.modules.filesys.service.ICooperationService;
import org.springblade.core.boot.ctrl.BladeController;

/**
 *  控制器
 *
 * @author Blade
 * @since 2022-01-02
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-filesys/cooperation")
@Api(value = "", tags = "文件共享系统-crud接口")
public class CooperationController extends BladeController {

	private ICooperationService cooperationService;


	@GetMapping("/info")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "过滤后的普通文件分享信息", notes = "传入sharing")
	public R<CooperationSimpleVO> detail1(Cooperation cooperation) {
		Cooperation detail = cooperationService.getOne(Condition.getQueryWrapper(cooperation));
		CooperationSimpleVO cooperationSimpleVO = BeanUtil.toBean(detail, CooperationSimpleVO.class);
		return R.data(cooperationSimpleVO);
	}
	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入cooperation")
	public R<Cooperation> detail(Cooperation cooperation) {
		Cooperation detail = cooperationService.getOne(Condition.getQueryWrapper(cooperation));
		return R.data(detail);
	}

	/**
	 * 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入cooperation")
	public R<IPage<Cooperation>> list(Cooperation cooperation, Query query) {
		Long userId = SecureUtil.getUserId();
		cooperation.setCreateUser(userId);
		IPage<Cooperation> pages = cooperationService.page(Condition.getPage(query), Condition.getQueryWrapper(cooperation));
		return R.data(pages);
	}

	/**
	 * 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入cooperation")
	public R<IPage<CooperationVO>> page(CooperationVO cooperation, Query query) {
		IPage<CooperationVO> pages = cooperationService.selectCooperationPage(Condition.getPage(query), cooperation);
		return R.data(pages);
	}

	/**
	 * 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入cooperation")
	public R save(@Valid @RequestBody Cooperation cooperation) {
		return R.status(cooperationService.save(cooperation));
	}

	/**
	 * 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入cooperation")
	public R update(@Valid @RequestBody Cooperation cooperation) {
		return R.status(cooperationService.updateById(cooperation));
	}

	/**
	 * 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入cooperation")
	public R submit(@Valid @RequestBody Cooperation cooperation) {
		return R.status(cooperationService.saveOrUpdate(cooperation));
	}


	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(cooperationService.removeByIds(Func.toLongList(ids)));
	}


}
